ProjectName.modules.CategoryListing = {
    init: function () {
        this.selectAllCheckbox();
        this.deleteSelector();
        this.deleteCateogory();
        this.searchSelector();
        this.tableSortor();
    } ,
    
    deleteCateogory : function () {
		$('.categorydelete').click(function(){
			jQuery('.category-delete-container').hide();
			jQuery('.category-product-delete-container').hide();
			var bool = confirm("Are you sure you want to delete this category?");
			if (bool) {				jQuery('#succcontainer').hide();				
				var categoryid =  $(this).attr('categoryid');
				categoryid = jQuery.trim(categoryid) ;
				var postdata = {};
				postdata['categoryid'] = categoryid;
				postdata['callback'] = 'categoryDelete';
				jQuery.post ( base_url+'admingeneral.ajax.php' , postdata , function (result){
					if (result == 'UNSUCCESS') {
						$('.category-delete-container').show();
					} else if (result == 'UNSUCESSPRODUCTEXIST') {	
						$('.category-product-delete-container').show();
					} else {
						window.location.href=window.location.href;
					}
					return false;
				});
			}
			return false;
		});
    	
    } ,

    tableSortor: function () {
        jQuery("#categorylisting-table").tablesorter({
            headers: {
                4: { sorter: false },
                5: { sorter: false }
            }
        });
    },
    
    selectAllCheckbox: function () {
        $('#selectall').click(function(){
            if ($(this).is(':checked') == true) {
                $('.content-checkbox').attr('checked', true);
            } else {
                $('.content-checkbox').attr('checked', false);
            }
        });
    },
    deleteSelector : function () {
        $('#show_all_button').click(function(){
            $('#search-status').val('');
            $('#searchtext').val('');
            $('#searchtype').val('');
            $('#searchparentategory').val('');

        });
        $('#multiaction').change(function(){
            $('#searchtype').val('');
            $('#search-status').val('');
            $('#searchtext').val('');
            $('#searchparentategory').val('');
        });
    },
    searchSelector : function () {
        $('#searchtext-container').show();
        $('#searchtype').change(function(){
            $('#multiaction').val('');
            $('.search-type').hide();
            var searchtype = jQuery.trim($(this).val());
            if (searchtype == 'title' || searchtype == 'description' ) {
                $('#searchtext-container').show();
                $('#search-status').val('');
                $('#search-parentcategory').val('');
            } else if (searchtype == 'status') {
                $('#searchtext').val('');
                $('#status-container').show();
                $('#search-parentcategory').val('');
		  } else if (searchtype == 'parentcategory') {
		  	$('#searchtext').val('');       
		  	$('#search-status').val('');
		  	$('#parentcategory-container').show();
            }else {
                $('#searchtext-container').show();
                $('#search-status').val('');
                $('#search-parentcategory').val('');
            }
        });
        $('#searchtype').trigger('change');
    }
}
